﻿<!--#include file="isLogin.aspx"-->
<script language="vbscript" runat="server">
dim FileBrowser_BasePath,FileBrowser_BasePath2,Files

Sub ListFiles()
	dim i
	Response.Write("<?xml version=""1.0"" encoding=""UTF-8""?>" & vbcrlf)
	Response.Write("<root>" & vbcrlf)
	Response.Write("<errdescription><![CDATA[]]></errdescription>" & vbcrlf)
	Dim it
	dim FSO As System.IO.Directory,mmFileInfo As System.IO.FileInfo

	Response.Write("<files>" & vbcrlf)
	For i=0 to Ubound(Files)
		if Files(i)<>"" then
			'Response.write(Server.Mappath(Files(i)))
			mmFileInfo=New System.IO.FileInfo(Server.Mappath(Files(i)))
			if mmFileInfo.Exists() then
				
				Response.Write("<file>" & vbcrlf)
				Response.Write("<filename><![CDATA[" & WebNoteHTMLEncode(CStr(Files(i))) & "]]></filename>" & vbcrlf)
				Response.Write("<fileexname>" & Replace(mmFileInfo.Extension,".","") & "</fileexname>" & vbcrlf)
				Response.Write("<filesize>" & mmFileInfo.Length() & "</filesize>" & vbcrlf)
				Response.Write("</file>" & vbcrlf)
			end if
		end if
	Next
	Fso=Nothing
	Response.Write("</files>" & vbcrlf)
	Response.Write("</root>" & vbcrlf)
End Sub


Sub ListFolder(Path)
	Response.ContentType = "text/xml"
	Response.Write("<?xml version=""1.0"" encoding=""UTF-8""?>" & vbcrlf)
	Response.Write("<root folderpath=""" & WebNoteHTMLEncode(Path) & """>" & vbcrlf)
	
	dim Flag0,Flag1
	if FileBrowser_BasePath<>"" then
	    Flag0=Not (Left(Path,len(FileBrowser_BasePath))<>FileBrowser_BasePath or InStr(Path,"../")>0)
	else	    
	    Flag0=true
	end if

	if FileBrowser_BasePath2<>"" then
	    Flag1=Not (Left(Path,len(FileBrowser_BasePath2))<>FileBrowser_BasePath2 or InStr(Path,"../")>0)
	else
	    Flag1=true
	end if
	
	Dim it
	dim FSO As System.IO.Directory,mmFileInfo As System.IO.FileInfo,mmDirectoryInfo As System.IO.DirectoryInfo
	
	if Not (Flag0 or Flag1) then
		Response.Write("<errdescription><![CDATA[Folder is hidden.]]></errdescription>" & vbcrlf)

	else
        if Not Fso.Exists(Server.Mappath(Path)) then
		    Response.Write("<errdescription><![CDATA[Folder is not exist.]]></errdescription>" & vbcrlf)
		else
			Response.Write("<errdescription><![CDATA[]]></errdescription>" & vbcrlf)

			Response.Write("<subfolders>" & vbcrlf)
			For Each it in Fso.GetDirectories(Server.Mappath(Path))
				mmDirectoryInfo = New System.IO.DirectoryInfo(it)
				Response.Write("<folder><![CDATA[" & WebNoteHTMLEncode(CStr(mmDirectoryInfo.Name))& "]]></folder>" & vbcrlf)
				mmDirectoryInfo = Nothing
			Next
			Response.Write("</subfolders>" & vbcrlf)
			Response.Write("<files>" & vbcrlf)
			For Each it in Fso.GetFiles(Server.Mappath(Path))
				mmFileInfo = New System.IO.FileInfo(it)
				Response.Write("<file>" & vbcrlf)
				Response.Write("<filename><![CDATA[" & WebNoteHTMLEncode(CStr(mmFileInfo.Name)) & "]]></filename>" & vbcrlf)
				Response.Write("<fileexname>" & Replace(mmFileInfo.Extension,".","") & "</fileexname>" & vbcrlf)
				Response.Write("<filesize>" & mmFileInfo.Length() & "</filesize>" & vbcrlf)
				Response.Write("</file>"& vbcrlf)
				mmFileInfo = Nothing
			Next
			Response.Write("</files>" & vbcrlf)
		end if
	end if
	Fso=Nothing

	Response.Write("</root>" & vbcrlf)
End Sub

Function GetRelativePath(sAbsolutePath)
	dim tempStr
	tempStr=Replace(Lcase(sAbsolutePath),Lcase(Server.Mappath("/")),"")
	GetRelativePath=Replace(tempStr,"\","/")
End Function

Function WebNoteHTMLEncode(sText)
	dim j,a,returnValue,AscwCode
	For j = 1 to Len (sText)
		a=Mid(sText, j, 1)
		AscwCode=Ascw(a)
		If AscwCode <0 or AscwCode >127 Then
			returnValue = returnValue & "&#x" & Hex(Ascw(a)) & ";"
		else
			returnValue = returnValue & a
		end if
	next
	WebNoteHTMLEncode = returnValue
End Function

</script>

<%

dim Path,act

act=Request("act")

Dim mmArtRight As New WebNote.FileRight
dim mmArt As New WebNote.WebNote
	FileBrowser_BasePath=Lcase(mmArtRight.Path)
	FileBrowser_BasePath2=Lcase(mmArt.DirectionPath)
mmArtRight=Nothing
mmArt=Nothing

if act=1 then
	Path=FileBrowser_BasePath2
	ListFolder(Lcase(Path))
elseif act=2 then
	'当前编辑内容包含的所有文件
	Files=Request.Form("Files")
	'Response.write(Files)
	Files=Split(Files,"||")
	ListFiles()
else
	Path=System.Text.RegularExpressions.Regex.UnEscape(Request.QueryString("FolderPath"))
	if Path="" then
		Path=FileBrowser_BasePath
	end if
	ListFolder(Lcase(Path))
end if

if Path="" then
	Response.end
end if




%>
